package framework
{
	import flash.events.Event;
	
	import mx.core.Application;
	

	public dynamic class CtxEvent extends Event
	{
		public var ctxName:String;
		public var alreadyDispatched:Boolean;
		public var commandName:String;
		
		public function CtxEvent(beanName:String,commandName:String = "act", ctxName:String = "default",autoDispatch:Boolean = true, bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(beanName, bubbles, cancelable);
			this.ctxName = ctxName;
			this.commandName = commandName;
			if (autoDispatch)
			{
				Application.application.callLater(internalDispatch);
			}
		}
		private function internalDispatch():void
		{
			if (!alreadyDispatched) dispatch();
		}
		public function dispatch():void
		{
			Ctx.contexts[ctxName].dispatchEvent(this);
			alreadyDispatched = true;
		}
		
	}
}